package com.scf.fruit.shiro;

import com.scf.fruit.user.FruitUserDto;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;

/**
 * @author : 孙超飞
 * @title :
 * @description :
 * @copyright :
 * @date : 2018-05-22 9:15
 */

public class AdminUserUtil {
    public static FruitUserDto getCurrentUser() {

        Session session = SecurityUtils.getSubject().getSession();
        if (session == null) {
            return null;
        }
        return (FruitUserDto) session.getAttribute("USER");
    }

    public static Long getCurrentUserID() {
        FruitUserDto user = getCurrentUser();
        if (user == null) {
            return null;
        }
        return user.getId();
    }

    public static void setCurrentUser(FruitUserDto user){
        Session session = SecurityUtils.getSubject().getSession();
        if (session == null) {
            return;
        }
        session.setAttribute("USER", user);
    }
}
